package com.tju.backend.service.business.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tju.backend.dao.ware.WarehousingMapper;
import com.tju.backend.entity.TWarehousing;
import com.tju.backend.service.business.IWarehousingService;
import com.tju.backend.utils.result.Result;
import com.tju.backend.utils.result.ResultEnum;
import com.tju.backend.utils.result.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author xt-exhibition
 * @date 2021-05-19
 */
@Service
public class WarehousingServiceImpl implements IWarehousingService {

    @Autowired
    private WarehousingMapper warehousingMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public TWarehousing selectWarehousingById(Integer id) {
        return warehousingMapper.selectWarehousingById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param warehousing 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<TWarehousing> selectWarehousingList(TWarehousing warehousing) {
        return warehousingMapper.selectWarehousingList(warehousing);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param warehousing 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertWarehousing(TWarehousing warehousing) {

        return warehousingMapper.insertWarehousing(warehousing);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param warehousing 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateWarehousing(TWarehousing warehousing) {
        return warehousingMapper.updateWarehousing(warehousing);
    }

    /**
     * 删除【请填写功能名称】对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWarehousingByIds(String ids) {
        return warehousingMapper.deleteWarehousingByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteWarehousingById(Integer id) {
        return warehousingMapper.deleteWarehousingById(id);
    }


    /**
     * 查询最新的十条数据
     *
     * @return
     */
    @Override
    public Result<Object> listWarehousing() {
        try {
            QueryWrapper<TWarehousing> wrapper = new QueryWrapper<>();
            wrapper.orderByDesc("warehousing_time");
            List<TWarehousing> data = warehousingMapper.selectList(wrapper);
            return ResultUtil.success(ResultEnum.SUCCESS, data);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(ResultEnum.UNKONW_ERROR);
        }
    }
}
